#include <chrono>
#include <iostream>
#include <format>
#include <unistd.h>
/*The <unistd. h> header defines miscellaneous symbolic constants and types,
and declares miscellaneous functions.
The actual values of the constants are unspecified except as shown.
*/
long Fibonacci(unsigned n)
{
    return n < 2 ? n : Fibonacci(n - 1) + Fibonacci(n - 2);
}

int main()
{
    const auto start{std::chrono::steady_clock::now()};
    const auto fb{Fibonacci(42)};
    const auto end{std::chrono::steady_clock::now()};
    const std::chrono::duration<double> elapsed_seconds{end - start};

    std::cout << "Fibonacci(42): " << fb << "\nElapsed time: ";
    //  std::cout << elapsed_seconds.count() << "s\n"; // Before C++20
    std::cout << elapsed_seconds << '\n'; // C++20's chrono::duration operator<<

    std::cout << "Fibonacci(42): " << fb << "\nElapsed time: ";
    //  std::cout << elapsed_seconds.count() << "s\n"; // Before C++20
    std::cout << elapsed_seconds << '\n'; // C++20's chrono::duration operator<<

    auto start2{std::chrono::high_resolution_clock::now()};

    auto sy_fb{Fibonacci(42)};

    auto finish2{std::chrono::high_resolution_clock::now()};
    std::cout << "\nFibonacci(42): " << fb << "\n";

    std::cout << std::format("Elapsed time in nanoseconds: {} ns\n", std::chrono::duration_cast<std::chrono::nanoseconds>(finish2 - start2).count());
    std::cout << std::format("Elapsed time in microseconds: {} µs\n", std::chrono::duration_cast<std::chrono::microseconds>(finish2 - start2).count());
    std::cout << std::format("Elapsed time in milliseconds: {} ms\n", std::chrono::duration_cast<std::chrono::milliseconds>(finish2 - start2).count());
    printf("Elapsed time in seconds: %ld sec\n", std::chrono::duration_cast<std::chrono::seconds>(finish2 - start2).count());

    start2 = std::chrono::high_resolution_clock::now();

    sy_fb = Fibonacci(42);

    finish2 = std::chrono::high_resolution_clock::now();
    std::cout << "\nFibonacci(42): " << fb << "\n";

    std::cout << std::format("Elapsed time in nanoseconds: {} ns\n", std::chrono::duration_cast<std::chrono::nanoseconds>(finish2 - start2).count());
    std::cout << std::format("Elapsed time in microseconds: {} µs\n", std::chrono::duration_cast<std::chrono::microseconds>(finish2 - start2).count());
    std::cout << std::format("Elapsed time in milliseconds: {} ms\n", std::chrono::duration_cast<std::chrono::milliseconds>(finish2 - start2).count());
    printf("Elapsed time in seconds: %ld sec\n", std::chrono::duration_cast<std::chrono::seconds>(finish2 - start2).count());
}